<template>
  <div class="body">
    <div class="formWrap">
      <el-form
        ref="form"
        :model="form"
        :rules="rules"
        label-width="80px"
        label-position="left"
        class="formWrap"
      >
        <el-form-item label="用户名" prop="goodsName">
          <el-input v-model="form.userName"></el-input>
        </el-form-item>

        <el-form-item label="密码" prop="goodsPrice">
          <el-input v-model="form.passWord" type="password"></el-input>
        </el-form-item>

        <el-form-item>
          <el-button style="width:320px" type="primary" @click="onSubmit('form')">登 录</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import api from "@/api";
export default {
  data() {
    return {
      form: {
        userName: "",
        passWord: "",
      },
      rules: {
        userName: [
          { required: true, message: "请输入用户名", trigger: "change" },
        ],
        passWord: [
          { password: true, message: "请输入密码", trigger: "change" },
        ],
      },
      goodsList: [],
    };
  },
  mounted() {},
  methods: {
    onSubmit(formName) {
      // console.log(this.form);
      this.$refs[formName].validate((valid) => {
        if (valid) {
          if (
            (this.form.userName == "zcq" && this.form.passWord == "zcq799") ||
            (this.form.userName == "hljs" && this.form.passWord == "hljs799") ||
            (this.form.userName == "lyh" && this.form.passWord == "123654")
            ) {
            this.$message({
              message: "登录成功",
              type: "success",
            });
            sessionStorage.setItem("userInfo",JSON.stringify(this.form))
		
            // console.log(localStorage.getItem("userInfo"))
            this.$router.push({path:'/home'})
          }else{
            this.$message("用户名或密码错误");
          }
        }
      });
    },
    reset(formName) {
      this.$refs[formName].resetFields();
    },
    shopChange(id) {
      this.goodsList.map((item, i) => {
        if (item.id == id) {
          this.form.goodsName = item.goodsName;
        }
      });
    },
  },
};
</script>

<style scoped>
.body {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  min-width: 1000px;
  z-index: -10;
  zoom: 1;
  background-color: #fff;
  background: url(../../assets/images/loginbg.jpg) no-repeat;
  background-size: cover;
  -webkit-background-size: cover;
  -o-background-size: cover;
  background-position: center 0;
}
.formWrap {
  width: 400px;
  height: 400px;
  margin: 200px auto;
}
</style>
